package com.big.app.controller;

import com.big.app.service.FoodsService;
import com.big.app.util.JedisUtils;
import com.big.app.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.GeoCoordinate;

import java.util.List;

@RequestMapping("/api/foods/")
@CrossOrigin
@RestController
@Api(value = "美食接口", tags = "美食接口")
public class FoodsController {
    @Autowired
    private FoodsService service;
    @GetMapping("listall.do")
    @ApiOperation( value = "查询全部美食")
    R queryListAll(){
        return service.queryListAll();
    }
    @GetMapping("detail.do")
    @ApiOperation( value = "查询美食详情")
    R queryDetail(int id){
        return service.queryDetail(id);
    }

    @ApiOperation( value = "根据name查询")
    @GetMapping("byName.do")
    R queryByName(String name){
        return service.queryListName(name);
    }
    @ApiOperation( value = "根据flag查询")
    @GetMapping("byFlag.do")
    R queryByFlag(int flag){
        return service.queryListType(flag);
    }
    @ApiOperation( value = "根据地址")
    @GetMapping("map.do")
    R queryByFlag(String name){
        if (JedisUtils.esists(name)) {
            List<GeoCoordinate> geo = JedisUtils.getGeo(name, name);
            return new R(200,geo);
        }else {
            return new R(400,null);
        }
    }

}
